﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommonLibrary.DataModel.Car;
using ServiceApplication.Dao.Car;
using System.Data;

namespace ServiceApplication.Service.Car
{
    public class CarService
    {
        CarDao carDao = new CarDao();
        ApplyDao applyDao = new ApplyDao();

        #region car

        public int CarAdd(CarEntity carEntity)
        {
            return carDao.AddEntity(carEntity);
        }

        public void CarDel(int car_id)
        {
            carDao.DeleteEntity(car_id);
        }

        public void CarUpdate(CarEntity carEntity)
        {
            carDao.UpdateEntity(carEntity);
        }

        public CarEntity CarQuery(int car_id)
        {
            var carEntity = carDao.QueryEntity(car_id);
            return carEntity;
        }

        public DataTable CarQueryAll()
        {
            return carDao.QueryAll();
        }

        public DataTable CarQuery(CarEntity carEntity)
        {
            return carDao.Query(carEntity);
        }

        #endregion

        #region car apply

        public int ApplyAdd(ApplyEntity applyEntity)
        {
            return applyDao.AddEntity(applyEntity);
        }

        public void ApplyDel(int apply_id)
        {
            applyDao.DeleteEntity(apply_id);
        }

        public void ApplyUpdate(ApplyEntity applyEntity)
        {
            applyDao.UpdateEntity(applyEntity);
        }

        public ApplyEntity ApplyQuery(int apply_id)
        {
            var applyEntity = applyDao.QueryEntity(apply_id);
            return applyEntity;
        }

        public DataTable ApplyQueryConflict(int apply_id)
        {
            var applyEntity = ApplyQuery(apply_id);
            if (applyEntity == null) return null;
            var dt = applyDao.QueryForConflict(applyEntity.apply_stime, applyEntity.apply_etime, applyEntity.car_id);
            return dt;
        }

        public DataTable ApplyQueryForCarState(string stime, string etime, int car_id)
        {
            var dt = applyDao.QueryForConflict(stime, etime, car_id);
            return dt;
        }

        public DataTable ApplyQuery(ApplyEntity applyEntity)
        {
            return applyDao.Query(applyEntity);
        }

        public DataTable ApplyQueryAll()
        {
            return applyDao.QueryAll();
        }


        /// <param name="apply_result">null,-1,0,1</param>
        /// <param name="timetype">time,stime,etime,cztime</param>
        public DataTable ApplyQueryByConditon(string sqr_id, string czr_id, string apply_result, string timetype, string stime, string etime)
        {
            return applyDao.QueryByCondition(sqr_id, czr_id, apply_result, timetype, stime, etime);
        }
        #endregion
    }
}
